import Vue from "vue";

import VueRouter from "vue-router";

Vue.use(VueRouter);

import Layout from "@/views/Layout.vue";
import Login from "@/views/Login.vue";

const router = new VueRouter({
  routes: [
    {
      path: "/login",
      name: "login",
      component: Login,
      meta: {
        hidden: true,
      },
    },
    {
      path: "/",
      name: "Home",
      redirect: "/users/index",
      meta: {
        hidden: true,
      },
    },

    {
      path: "/users",
      redirect: { path: "/users/index" },
      component: Layout,
      name: "users",
      meta: {
        name: "用户",
      },
      children: [
        {
          path: "index",
          name: "users-index",
          component: () => import("@/views/Users.vue"),
          meta: {
            name: "用户管理",
            auth: ["user"],
          },
        },
        {
          path: "add",
          name: "users-add",
          component: () => import("@/views/UsersAdd.vue"),
          meta: {
            name: "用户添加",
            auth: ["admin"],
          },
        },
        {
          path: "edit",
          name: "users-edit",
          component: () => import("@/views/UsersEdit.vue"),
          meta: {
            name: "用户编辑",
            auth: ["user"],
          },
        },
      ],
    },
    {
      path: "/posts",
      component: Layout,
      name: "posts",
      meta: {
        name: "文章",
      },
      children: [
        {
          path: "index",
          component: () => import("@/views/Posts.vue"),
          name: "posts-index",
          meta: {
            name: "文章管理",
            auth: ["admin", "student"],
          },
        },
      ],
    },
    {
      path: "/comments",
      component: Layout,
      name: "comments",
      meta: {
        name: "评论",
      },
      children: [
        {
          path: "index",
          name: "comments-index",
          component: () => import("@/views/Comments.vue"),
          meta: {
            name: "评论添加",
            auth: ["student"],
          },
        },
      ],
    },
  ],
});

export default router;
